import xlrd


def get_excel_data(excel_path, n_col):
    # 文件路径
    # 1、打开文件，获取excel文件workbook对象
    excel = xlrd.open_workbook(excel_path)

    # 2、获取所有/指定sheet对象
    # all_sheet = excel.sheets()
    sheet = excel.sheet_by_index(1)

    # 3、获取指定列
    print(f"该sheet共有{sheet.nrows}行数据")

    data = []
    for i in range(2, sheet.nrows):
        data.append(sheet.row_values(i)[:n_col])

    return data


if __name__ == '__main__':
    excel_path = 'D:\作业\需求\人员信息表.xls'
    # 取前两列数据
    data = get_excel_data(excel_path, n_col=2)

    # for item in data:
    #     print(
    #         f"""insert into XXX(aaa,bbb,ccc,ddd,ee,ff) values ('2','{item[0]}','{item[1]}',null,null,null);""")

    with open('sqlData.sql', 'a') as f:
        for item in data:
            temp = f"""获取excel文件workbook对象;"""
            f.write(temp + "\n")